<!-- saved from url=(0016)http://localhost -->
var xml=loadXMLDoc("guncase.xml");
var xsl=loadXMLDoc("guncase.xsl");

var elemXPath=xsl.getElementsByTagName("xsl:for-each")[0];

var index = 0;

var path="/guncase/gun/maker";
var nodes=xml.selectNodes( path );
var length = nodes.length;

//Display XML file transformed to XSL style
function displayResult(path)
{
	elemXPath.setAttribute("select",path);
	
	// code for IE
	if (window.ActiveXObject)
	{
		ex=xml.transformNode(xsl);
		document.getElementById("example").innerHTML=ex;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	{
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		resultDocument = xsltProcessor.transformToFragment(xml,document);
		document.getElementById("example").appendChild(resultDocument);
	}
}

//Load files create new request object
function loadXMLDoc(dname)
{//synchronous ajax request
	if (window.XMLHttpRequest)
	{
		xhttp=new XMLHttpRequest();
	}
	else
	{
		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhttp.open("GET",dname,false);
	xhttp.send("");
	return xhttp.responseXML;	
}

function indexUpdate(index)
{
	
	if ( index>=0 && index<length )
	{	
	    path = "guncase/gun["+(parseInt(index)+1)+"]";
	    document.getElementById("num").value=index+1;
        displayResult(path)
	}
}

function next()
{

    if ( index < length-1 )
	{
	    index++;
	    indexUpdate(index);
	 }
}

function previous()
{
	if (index > 0)
	{
	   	index--;
	    indexUpdate(index);
	}

}

function update()
{
    var value = parseInt(document.getElementById("num").value)-1;
    if (value!=NaN && value!="" && value>=0 && value<length )
    { 
        index = value;    
    }
    indexUpdate(index); 
}

